/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ws;

import logManagement.Log4k;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
 *
 * @author Lorenzo
 */
class GeonamesHandler extends DefaultHandler
{
    boolean toponym = false;
    boolean name = false;
    boolean lat = false;
    boolean lng = false;
    boolean wikiUrl = false;
    
    String rlat, rlng, url;

    public String getCoord(){
        return rlat + ", " + rlng;
    }
    
    public String getUrl(){
        return url;
    }

    @Override
    public void startElement(String uri, String localName,
         String gName, Attributes attributes) throws SAXException
    {
      Log4k.debug(this.getClass().getName(), "Elemento Iniziale: " + gName);
      if (gName.equalsIgnoreCase("toponymName"))
         toponym = true;
      if (gName.equalsIgnoreCase("name"))
         name = true;
      if (gName.equalsIgnoreCase("lat"))
         lat = true;
      if (gName.equalsIgnoreCase("lng"))
         lng = true;
      if (gName.equalsIgnoreCase("wikipediaUrl"))
         wikiUrl = true;
    }

    @Override
    public void endElement(String uri, String localName,
         String gName) throws SAXException
    {
      Log4k.debug(this.getClass().getName(), "Elemento Finale: " + gName);
    }

    @Override
    public void characters(char ch[], int start, int length)
         throws SAXException
    {
       if (toponym)
       {
          Log4k.debug(this.getClass().getName(), "Toponimo: " + new String(ch, start, length));
          toponym = false;
       }
       if (name)
       {
          Log4k.debug(this.getClass().getName(), "Nome: " + new String(ch, start, length));
          name = false;
       }
       if (lat)
       {
          Log4k.debug(this.getClass().getName(), "Latitudine: " + new String(ch, start, length));
          rlat = new String(ch, start, length);
          lat = false;
       }
       if (lng)
       {
          Log4k.debug(this.getClass().getName(), "Longitudine: " + new String(ch, start, length));
          rlng = new String(ch, start, length);
          lng = false;
       }
       if (wikiUrl)
       {
          Log4k.debug(this.getClass().getName(), "wikipediaUrl: " + new String(ch, start, length));
          url = new String(ch, start, length);
          wikiUrl = false;
       }
     }
}